﻿using AutoMapper.Configuration.Conventions;
using DFGK_WMS.Model.Models;
using SqlSugar;

namespace DFGJ.WMS_PDA.WebAPI.Extensions
{  
    /// <summary>
    /// 初始化数据库
    /// </summary>
    public static class InitDBExtend
    {   
        /// <summary>
        /// 生成表 
        /// </summary>
        /// <param name="builder"></param>
        /// <exception cref="Exception"></exception>
        public static void AddDBTableSetUp(this WebApplicationBuilder builder)
        {
            string key = builder.Configuration["IsInitDatabase"];
            if (key != "1")
            {
                return;
            }
            string? connectionString = builder.Configuration.GetSection("ConnectionStrings").GetSection("DFGK_WMS").Value;
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception("请配置数据库链接字符串~");
            }
            
            ConnectionConfig config = new ConnectionConfig()
            {
                ConnectionString = connectionString,
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true
            };
            using (ISqlSugarClient client = new SqlSugarClient(config))
            {
                client.DbFirst.Where(it=>it== "TStations")
                    .IsCreateAttribute()
                    .StringNullable() 
                    .CreateClassFile("D:\\东方国凯\\WMS\\DongFangGuoKaiWMS\\DFGK_WMS.Model\\Models\\PDA");

            }







        }
    }
}
